<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>购物车 - Surreal Gallery 超现实主义数字藏品平台</title>
    <!-- 引入Font Awesome 6.4.0图标库 -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        /* 继承首页样式变量 */
        :root {
            --primary: #6a11cb;
            --secondary: #2575fc;
            --accent: #ff2e63;
            --dark: #1a1a2e;
            --light: #f0f0f0;
            --surreal-purple: #8a2be2;
            --surreal-blue: #00b4d8;
            --surreal-pink: #ff6b6b;
            --surreal-yellow: #f9d423;
            --surreal-green: #2ecc71;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }

        body {
            background: linear-gradient(135deg, var(--dark) 0%, #16213e 100%);
            color: var(--light);
            overflow-x: hidden;
            min-height: 100vh;
        }

        /* 超现实主义背景元素 */
        .floating-elements {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            pointer-events: none;
            z-index: -1;
        }

        .floating-element {
            position: absolute;
            border-radius: 50%;
            opacity: 0.1;
            filter: blur(40px);
            animation: float 15s infinite ease-in-out;
        }

        .floating-element:nth-child(1) {
            width: 300px;
            height: 300px;
            background: var(--surreal-purple);
            top: 10%;
            left: 5%;
            animation-delay: 0s;
        }

        .floating-element:nth-child(2) {
            width: 200px;
            height: 200px;
            background: var(--surreal-blue);
            top: 60%;
            right: 10%;
            animation-delay: 3s;
        }

        .floating-element:nth-child(3) {
            width: 250px;
            height: 250px;
            background: var(--surreal-pink);
            bottom: 10%;
            left: 20%;
            animation-delay: 6s;
        }

        @keyframes float {

            0%,
            100% {
                transform: translateY(0) rotate(0deg);
            }

            50% {
                transform: translateY(-20px) rotate(180deg);
            }
        }

        /* 导航栏 */
        header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 20px 5%;
            position: fixed;
            width: 100%;
            z-index: 1000;
            background: rgba(26, 26, 46, 0.8);
            backdrop-filter: blur(10px);
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        }

        .logo {
            font-size: 28px;
            font-weight: 700;
            background: linear-gradient(45deg, var(--surreal-purple), var(--surreal-blue));
            -webkit-background-clip: text;
            background-clip: text;
            color: transparent;
            text-shadow: 0 0 10px rgba(138, 43, 226, 0.3);
        }

        nav ul {
            display: flex;
            list-style: none;
        }

        nav ul li {
            margin-left: 30px;
        }

        nav ul li a {
            color: var(--light);
            text-decoration: none;
            font-weight: 500;
            transition: all 0.3s ease;
            position: relative;
        }

        nav ul li a:hover {
            color: var(--surreal-pink);
        }

        nav ul li a::after {
            content: '';
            position: absolute;
            width: 0;
            height: 2px;
            bottom: -5px;
            left: 0;
            background: linear-gradient(45deg, var(--surreal-purple), var(--surreal-blue));
            transition: width 0.3s ease;
        }

        nav ul li a:hover::after {
            width: 100%;
        }

        .cta-button {
            background: linear-gradient(45deg, var(--surreal-purple), var(--surreal-blue));
            color: white;
            border: none;
            padding: 10px 25px;
            border-radius: 30px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            box-shadow: 0 5px 15px rgba(106, 17, 203, 0.4);
        }

        .cta-button:hover {
            transform: translateY(-3px);
            box-shadow: 0 8px 20px rgba(106, 17, 203, 0.6);
        }

        /* 页面标题区域 */
        .page-header {
            padding: 150px 5% 80px;
            text-align: center;
            position: relative;
        }

        .page-title {
            font-size: 3.5rem;
            margin-bottom: 20px;
            background: linear-gradient(45deg, var(--surreal-purple), var(--surreal-blue), var(--surreal-pink));
            -webkit-background-clip: text;
            background-clip: text;
            color: transparent;
            line-height: 1.2;
        }

        .page-subtitle {
            font-size: 1.2rem;
            max-width: 600px;
            margin: 0 auto;
            opacity: 0.8;
            line-height: 1.6;
        }

        /* 购物车容器 */
        .cart-container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 5% 100px;
            display: grid;
            grid-template-columns: 2fr 1fr;
            gap: 40px;
        }

        /* 购物车内容 */
        .cart-content {
            background: rgba(255, 255, 255, 0.05);
            border-radius: 20px;
            padding: 30px;
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.1);
        }

        .section-title {
            font-size: 1.8rem;
            margin-bottom: 25px;
            color: var(--surreal-blue);
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .section-title i {
            font-size: 1.5rem;
        }

        /* 购物车项目 */
        .cart-items {
            display: flex;
            flex-direction: column;
            gap: 20px;
        }

        .cart-item {
            display: flex;
            gap: 20px;
            padding: 20px;
            background: rgba(255, 255, 255, 0.03);
            border-radius: 15px;
            transition: all 0.3s ease;
            border: 1px solid rgba(255, 255, 255, 0.05);
        }

        .cart-item:hover {
            background: rgba(255, 255, 255, 0.07);
            transform: translateY(-3px);
        }

        .item-image {
            width: 120px;
            height: 120px;
            border-radius: 10px;
            background: linear-gradient(45deg, var(--surreal-purple), var(--surreal-blue));
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 2.5rem;
            color: white;
            flex-shrink: 0;
        }

        .item-details {
            flex-grow: 1;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
        }

        .item-title {
            font-size: 1.3rem;
            margin-bottom: 8px;
        }

        .item-artist {
            font-size: 0.95rem;
            opacity: 0.8;
            margin-bottom: 10px;
        }

        .item-price {
            font-size: 1.2rem;
            font-weight: 700;
            color: var(--surreal-pink);
        }

        .item-controls {
            display: flex;
            align-items: center;
            gap: 15px;
        }

        .quantity-control {
            display: flex;
            align-items: center;
            gap: 10px;
            background: rgba(255, 255, 255, 0.05);
            border-radius: 20px;
            padding: 5px 15px;
        }

        .quantity-btn {
            background: transparent;
            border: none;
            color: var(--light);
            font-size: 1.2rem;
            cursor: pointer;
            width: 30px;
            height: 30px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 50%;
            transition: all 0.3s ease;
        }

        .quantity-btn:hover {
            background: rgba(255, 255, 255, 0.1);
        }

        .quantity {
            font-weight: 600;
            min-width: 30px;
            text-align: center;
        }

        .remove-btn {
            background: rgba(255, 255, 255, 0.05);
            border: none;
            color: var(--light);
            padding: 8px 15px;
            border-radius: 20px;
            cursor: pointer;
            transition: all 0.3s ease;
            display: flex;
            align-items: center;
            gap: 5px;
        }

        .remove-btn:hover {
            background: rgba(255, 71, 87, 0.2);
            color: var(--surreal-pink);
        }

        /* 空购物车状态 */
        .empty-cart {
            text-align: center;
            padding: 60px 20px;
        }

        .empty-cart-icon {
            font-size: 5rem;
            color: var(--surreal-purple);
            margin-bottom: 20px;
            opacity: 0.5;
        }

        .empty-cart h3 {
            font-size: 1.8rem;
            margin-bottom: 15px;
        }

        .empty-cart p {
            opacity: 0.7;
            margin-bottom: 30px;
        }

        /* 购物车侧边栏 */
        .cart-sidebar {
            display: flex;
            flex-direction: column;
            gap: 30px;
        }

        .summary-card {
            background: rgba(255, 255, 255, 0.05);
            border-radius: 20px;
            padding: 25px;
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.1);
        }

        .summary-row {
            display: flex;
            justify-content: space-between;
            margin-bottom: 15px;
            padding-bottom: 15px;
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        }

        .summary-row:last-child {
            border-bottom: none;
            margin-bottom: 0;
            padding-bottom: 0;
            font-weight: 700;
            font-size: 1.2rem;
        }

        .total-price {
            color: var(--surreal-pink);
            font-size: 1.4rem;
        }

        .checkout-button {
            width: 100%;
            padding: 15px;
            background: linear-gradient(45deg, var(--surreal-purple), var(--surreal-blue));
            color: white;
            border: none;
            border-radius: 30px;
            font-size: 1.1rem;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            margin-top: 20px;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 10px;
        }

        .checkout-button:hover {
            transform: translateY(-3px);
            box-shadow: 0 8px 20px rgba(106, 17, 203, 0.6);
        }

        .checkout-button:disabled {
            background: rgba(255, 255, 255, 0.1);
            color: rgba(255, 255, 255, 0.5);
            cursor: not-allowed;
            transform: none;
            box-shadow: none;
        }

        /* 推荐商品 */
        .recommendations {
            margin-top: 60px;
        }

        .recommendations-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
            gap: 25px;
            margin-top: 30px;
        }

        .recommendation-card {
            background: rgba(255, 255, 255, 0.05);
            border-radius: 15px;
            overflow: hidden;
            transition: all 0.3s ease;
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.1);
        }

        .recommendation-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
        }

        .recommendation-image {
            width: 100%;
            height: 150px;
            background: linear-gradient(45deg, var(--surreal-purple), var(--surreal-blue));
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 2.5rem;
            color: white;
        }

        .recommendation-content {
            padding: 15px;
        }

        .recommendation-title {
            font-size: 1.1rem;
            margin-bottom: 8px;
            line-height: 1.3;
        }

        .recommendation-price {
            font-weight: 700;
            color: var(--surreal-pink);
            margin-bottom: 10px;
        }

        .add-to-cart-btn {
            width: 100%;
            padding: 8px;
            background: rgba(255, 255, 255, 0.1);
            color: var(--light);
            border: none;
            border-radius: 20px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .add-to-cart-btn:hover {
            background: linear-gradient(45deg, var(--surreal-purple), var(--surreal-blue));
        }

        /* 页脚 */
        footer {
            background: rgba(0, 0, 0, 0.5);
            padding: 50px 5% 20px;
        }

        .footer-content {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 40px;
            margin-bottom: 40px;
        }

        .footer-column h3 {
            font-size: 1.2rem;
            margin-bottom: 20px;
            color: var(--surreal-blue);
        }

        .footer-column ul {
            list-style: none;
        }

        .footer-column ul li {
            margin-bottom: 10px;
        }

        .footer-column ul li a {
            color: var(--light);
            text-decoration: none;
            opacity: 0.7;
            transition: all 0.3s ease;
        }

        .footer-column ul li a:hover {
            opacity: 1;
            color: var(--surreal-pink);
        }

        .social-links {
            display: flex;
            gap: 15px;
            margin-top: 20px;
        }

        .social-link {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background: rgba(255, 255, 255, 0.1);
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.3s ease;
        }

        .social-link:hover {
            background: var(--surreal-purple);
            transform: translateY(-3px);
        }

        .social-links a {
            text-decoration: none;
            color: #fff;
        }

        .copyright {
            text-align: center;
            padding-top: 20px;
            border-top: 1px solid rgba(255, 255, 255, 0.1);
            opacity: 0.7;
        }

        /* 响应式设计 */
        @media (max-width: 968px) {
            .page-title {
                font-size: 2.8rem;
            }

            .cart-container {
                grid-template-columns: 1fr;
            }

            .recommendations-grid {
                grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
            }
        }

        @media (max-width: 768px) {
            nav ul {
                display: none;
            }

            .page-header {
                padding: 130px 5% 60px;
            }

            .page-title {
                font-size: 2.2rem;
            }

            .cart-item {
                flex-direction: column;
                text-align: center;
            }

            .item-image {
                width: 100%;
                height: 200px;
            }

            .item-controls {
                justify-content: center;
            }
        }
    </style>
</head>

<body>
    <!-- 超现实主义背景元素 -->
    <div class="floating-elements">
        <div class="floating-element"></div>
        <div class="floating-element"></div>
        <div class="floating-element"></div>
    </div>

    <!-- 导航栏 -->
    <header>
        <div class="logo">Surreal Gallery</div>
        <nav>
            <ul>
                <li><a href="index.html">首页</a></li>
                <li><a href="collections.html">数字藏品</a></li>
                <li><a href="artists.html">艺术家</a></li>
                <li><a href="news.html">新闻动态</a></li>
                <li><a href="#faq">常见问题</a></li>
            </ul>
        </nav>
        <button class="cta-button">连接钱包</button>
    </header>

    <!-- 页面标题区域 -->
    <section class="page-header">
        <h1 class="page-title">购物车</h1>
        <p class="page-subtitle">查看您选择的超现实主义数字藏品，准备完成购买</p>
    </section>

    <!-- 购物车容器 -->
    <section class="cart-container">
        <!-- 购物车内容 -->
        <div class="cart-content">
            <h2 class="section-title"><i class="fas fa-shopping-cart"></i> 购物车商品</h2>

            <div class="cart-items" id="cartItems">
                <!-- 购物车项目将通过JavaScript动态生成 -->
            </div>

            <!-- 空购物车状态 -->
            <div class="empty-cart" id="emptyCart" style="display: none;">
                <div class="empty-cart-icon"><i class="fas fa-shopping-cart"></i></div>
                <h3>您的购物车是空的</h3>
                <p>探索我们的超现实主义数字藏品，发现您喜爱的艺术品</p>
                <a href="collections.html" class="cta-button">开始购物</a>
            </div>
        </div>

        <!-- 购物车侧边栏 -->
        <div class="cart-sidebar">
            <div class="summary-card">
                <h3 class="section-title"><i class="fas fa-receipt"></i> 订单摘要</h3>
                <div class="summary-row">
                    <span>小计</span>
                    <span id="subtotal">0 ETH</span>
                </div>
                <div class="summary-row">
                    <span>服务费</span>
                    <span id="serviceFee">0 ETH</span>
                </div>
                <div class="summary-row">
                    <span>总计</span>
                    <span class="total-price" id="totalPrice">0 ETH</span>
                </div>
                <button class="checkout-button" id="checkoutButton" disabled>
                    <i class="fas fa-lock"></i> 前往结算
                </button>
            </div>

            <div class="summary-card">
                <h3 class="section-title"><i class="fas fa-shield-alt"></i> 购买保障</h3>
                <ul style="list-style: none; line-height: 1.8;">
                    <li><i class="fas fa-check" style="color: var(--surreal-green); margin-right: 10px;"></i> 正品保证</li>
                    <li><i class="fas fa-check" style="color: var(--surreal-green); margin-right: 10px;"></i> 区块链认证</li>
                    <li><i class="fas fa-check" style="color: var(--surreal-green); margin-right: 10px;"></i> 安全交易</li>
                    <li><i class="fas fa-check" style="color: var(--surreal-green); margin-right: 10px;"></i> 7天无忧退换
                    </li>
                </ul>
            </div>
        </div>
    </section>

    <!-- 推荐商品 -->
    <section class="cart-container recommendations">
        <div class="cart-content">
            <h2 class="section-title"><i class="fas fa-star"></i> 推荐商品</h2>
            <div class="recommendations-grid">
                <!-- 推荐商品 1 -->
                <div class="recommendation-card">
                    <div class="recommendation-image"><i class="fas fa-moon"></i></div>
                    <div class="recommendation-content">
                        <h4 class="recommendation-title">月光交响曲</h4>
                        <div class="recommendation-price">3.8 ETH</div>
                        <button class="add-to-cart-btn" data-id="6" data-title="月光交响曲" data-price="3.8"
                            data-icon="fa-moon">加入购物车</button>
                    </div>
                </div>

                <!-- 推荐商品 2 -->
                <div class="recommendation-card">
                    <div class="recommendation-image"><i class="fas fa-feather"></i></div>
                    <div class="recommendation-content">
                        <h4 class="recommendation-title">幻影蝴蝶</h4>
                        <div class="recommendation-price">1.2 ETH</div>
                        <button class="add-to-cart-btn" data-id="7" data-title="幻影蝴蝶" data-price="1.2"
                            data-icon="fa-feather">加入购物车</button>
                    </div>
                </div>

                <!-- 推荐商品 3 -->
                <div class="recommendation-card">
                    <div class="recommendation-image"><i class="fas fa-infinity"></i></div>
                    <div class="recommendation-content">
                        <h4 class="recommendation-title">无限循环</h4>
                        <div class="recommendation-price">2.5 ETH</div>
                        <button class="add-to-cart-btn" data-id="8" data-title="无限循环" data-price="2.5"
                            data-icon="fa-infinity">加入购物车</button>
                    </div>
                </div>

                <!-- 推荐商品 4 -->
                <div class="recommendation-card">
                    <div class="recommendation-image"><i class="fas fa-atom"></i></div>
                    <div class="recommendation-content">
                        <h4 class="recommendation-title">量子纠缠</h4>
                        <div class="recommendation-price">4.2 ETH</div>
                        <button class="add-to-cart-btn" data-id="9" data-title="量子纠缠" data-price="4.2"
                            data-icon="fa-atom">加入购物车</button>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- 页脚 -->
    <footer>
        <div class="footer-content">
            <div class="footer-column">
                <h3>Surreal Gallery</h3>
                <p>探索超现实数字艺术的新维度，发现独一无二的数字藏品。</p>
                <div class="social-links">
                    <a href="#" class="social-link"><i class="fab fa-facebook-f"></i></a>
                    <a href="#" class="social-link"><i class="fab fa-twitter"></i></a>
                    <a href="#" class="social-link"><i class="fab fa-instagram"></i></a>
                    <a href="#" class="social-link"><i class="fab fa-weixin"></i></a>
                </div>
            </div>
            <div class="footer-column">
                <h3>快速链接</h3>
                <ul>
                    <li><a href="index.html">首页</a></li>
                    <li><a href="collections.html">数字藏品</a></li>
                    <li><a href="artists.html">艺术家</a></li>
                    <li><a href="news.html">新闻动态</a></li>
                </ul>
            </div>
            <div class="footer-column">
                <h3>支持</h3>
                <ul>
                    <li><a href="#"><i class="fas fa-question-circle"></i> 帮助中心</a></li>
                    <li><a href="#"><i class="fas fa-envelope"></i> 联系我们</a></li>
                    <li><a href="#"><i class="fas fa-users"></i> 社区指南</a></li>
                    <li><a href="#"><i class="fas fa-file-alt"></i> 服务条款</a></li>
                </ul>
            </div>
            <div class="footer-column">
                <h3>订阅更新</h3>
                <p>订阅我们的新闻通讯，获取最新藏品和活动信息。</p>
                <form>
                    <input type="email" placeholder="您的电子邮箱"
                        style="width: 100%; padding: 10px; margin: 10px 0; border-radius: 5px; border: none; background: rgba(255,255,255,0.1); color: white;">
                    <button type="submit" class="cta-button" style="width: 100%;">订阅</button>
                </form>
            </div>
        </div>
        <div class="copyright">
            <p>&copy; 2023 Surreal Gallery. 保留所有权利。</p>
        </div>
    </footer>

    <script>
        // 购物车数据
        let cartItems = JSON.parse(localStorage.getItem('surrealCart')) || [];

        // 初始化购物车
        function initCart() {
            renderCartItems();
            updateCartSummary();
            updateEmptyState();
        }

        // 渲染购物车项目
        function renderCartItems() {
            const cartItemsContainer = document.getElementById('cartItems');
            cartItemsContainer.innerHTML = '';

            cartItems.forEach((item, index) => {
                const cartItemElement = document.createElement('div');
                cartItemElement.className = 'cart-item';
                cartItemElement.innerHTML = `
                    <div class="item-image">
                        <i class="fas ${item.icon}"></i>
                    </div>
                    <div class="item-details">
                        <div>
                            <h3 class="item-title">${item.title}</h3>
                            <p class="item-artist">艺术家: ${item.artist || 'Surreal Gallery'}</p>
                            <div class="item-price">${item.price} ETH</div>
                        </div>
                        <div class="item-controls">
                            <div class="quantity-control">
                                <button class="quantity-btn minus" data-index="${index}">-</button>
                                <span class="quantity">${item.quantity}</span>
                                <button class="quantity-btn plus" data-index="${index}">+</button>
                            </div>
                            <button class="remove-btn" data-index="${index}">
                                <i class="fas fa-trash"></i> 删除
                            </button>
                        </div>
                    </div>
                `;
                cartItemsContainer.appendChild(cartItemElement);
            });

            // 添加事件监听器
            document.querySelectorAll('.quantity-btn.minus').forEach(btn => {
                btn.addEventListener('click', function () {
                    const index = parseInt(this.getAttribute('data-index'));
                    updateQuantity(index, -1);
                });
            });

            document.querySelectorAll('.quantity-btn.plus').forEach(btn => {
                btn.addEventListener('click', function () {
                    const index = parseInt(this.getAttribute('data-index'));
                    updateQuantity(index, 1);
                });
            });

            document.querySelectorAll('.remove-btn').forEach(btn => {
                btn.addEventListener('click', function () {
                    const index = parseInt(this.getAttribute('data-index'));
                    removeItem(index);
                });
            });
        }

        // 更新商品数量
        function updateQuantity(index, change) {
            if (cartItems[index]) {
                cartItems[index].quantity += change;

                // 如果数量为0，则移除商品
                if (cartItems[index].quantity <= 0) {
                    cartItems.splice(index, 1);
                }

                saveCart();
                initCart();
            }
        }

        // 移除商品
        function removeItem(index) {
            if (cartItems[index]) {
                cartItems.splice(index, 1);
                saveCart();
                initCart();
            }
        }

        // 更新购物车摘要
        function updateCartSummary() {
            const subtotal = cartItems.reduce((sum, item) => {
                return sum + (parseFloat(item.price) * item.quantity);
            }, 0);

            const serviceFee = subtotal * 0.05; // 5%服务费
            const totalPrice = subtotal + serviceFee;

            document.getElementById('subtotal').textContent = subtotal.toFixed(2) + ' ETH';
            document.getElementById('serviceFee').textContent = serviceFee.toFixed(2) + ' ETH';
            document.getElementById('totalPrice').textContent = totalPrice.toFixed(2) + ' ETH';

            // 更新结算按钮状态
            const checkoutButton = document.getElementById('checkoutButton');
            if (cartItems.length > 0) {
                checkoutButton.disabled = false;
                checkoutButton.textContent = `前往结算 (${totalPrice.toFixed(2)} ETH)`;
            } else {
                checkoutButton.disabled = true;
                checkoutButton.textContent = '前往结算';
            }
        }

        // 更新空购物车状态
        function updateEmptyState() {
            const emptyCart = document.getElementById('emptyCart');
            const cartItemsContainer = document.getElementById('cartItems');

            if (cartItems.length === 0) {
                emptyCart.style.display = 'block';
                cartItemsContainer.style.display = 'none';
            } else {
                emptyCart.style.display = 'none';
                cartItemsContainer.style.display = 'flex';
            }
        }

        // 保存购物车到本地存储
        function saveCart() {
            localStorage.setItem('surrealCart', JSON.stringify(cartItems));
        }

        // 添加商品到购物车
        function addToCart(id, title, price, icon, artist = 'Surreal Gallery') {
            // 检查商品是否已在购物车中
            const existingItemIndex = cartItems.findIndex(item => item.id === id);

            if (existingItemIndex !== -1) {
                // 如果已存在，增加数量
                cartItems[existingItemIndex].quantity += 1;
            } else {
                // 如果不存在，添加新商品
                cartItems.push({
                    id,
                    title,
                    price: parseFloat(price).toFixed(2),
                    icon,
                    artist,
                    quantity: 1
                });
            }

            saveCart();
            initCart();

            // 显示添加成功提示
            showNotification(`"${title}" 已添加到购物车`);
        }

        // 显示通知
        function showNotification(message) {
            // 创建通知元素
            const notification = document.createElement('div');
            notification.style.cssText = `
                position: fixed;
                top: 100px;
                right: 20px;
                background: linear-gradient(45deg, var(--surreal-purple), var(--surreal-blue));
                color: white;
                padding: 15px 25px;
                border-radius: 10px;
                box-shadow: 0 5px 15px rgba(0,0,0,0.3);
                z-index: 10000;
                transform: translateX(150%);
                transition: transform 0.3s ease;
                max-width: 300px;
            `;
            notification.textContent = message;

            document.body.appendChild(notification);

            // 显示通知
            setTimeout(() => {
                notification.style.transform = 'translateX(0)';
            }, 100);

            // 3秒后隐藏并移除通知
            setTimeout(() => {
                notification.style.transform = 'translateX(150%)';
                setTimeout(() => {
                    document.body.removeChild(notification);
                }, 300);
            }, 3000);
        }

        // 初始化页面
        document.addEventListener('DOMContentLoaded', function () {
            initCart();

            // 添加推荐商品的事件监听器
            document.querySelectorAll('.add-to-cart-btn').forEach(btn => {
                btn.addEventListener('click', function () {
                    const id = this.getAttribute('data-id');
                    const title = this.getAttribute('data-title');
                    const price = this.getAttribute('data-price');
                    const icon = this.getAttribute('data-icon');

                    addToCart(id, title, price, icon);
                });
            });

            // 结算按钮事件
            document.getElementById('checkoutButton').addEventListener('click', function () {
                if (cartItems.length > 0) {
                    // 这里可以添加结算逻辑
                    alert('即将跳转到结算页面...');
                    // window.location.href = 'checkout.html';
                }
            });

            // 平滑滚动
            document.querySelectorAll('nav a').forEach(anchor => {
                anchor.addEventListener('click', function (e) {
                    if (this.getAttribute('href').startsWith('#')) {
                        e.preventDefault();

                        const targetId = this.getAttribute('href');
                        const targetElement = document.querySelector(targetId);

                        if (targetElement) {
                            window.scrollTo({
                                top: targetElement.offsetTop - 80,
                                behavior: 'smooth'
                            });
                        }
                    }
                });
            });
        });
    </script>
</body>

</html>